import React, { Component } from "react";
import MyCarousel from "../../compoents/MyCarousel";
import MyNavigation from "../../compoents/MyNavigation";
import MyRentingGroup from "../../compoents/MyRentingGroup";
import MyNewx from "../../compoents/MyNews";

import MySearch from "../../compoents/MySearch";

import { connect } from "react-redux";

class Index extends Component {
  state = {
    city_lable: "",
  };

  NavigationRoute = (pathName) => {
    this.props.history.push(pathName);
  };
  componentDidMount() {
    if (localStorage.getItem("cache_city_msg")) {
      const { label } = JSON.parse(localStorage.getItem("cache_city_msg"));
      this.setState({ city_lable: label });
    }
  }

  render() {
    const { curCity } = this.props;
    const { city_lable } = this.state;

    return (
      <div className="indexWrapper">
        {/* 搜索框 */}
        <MySearch
          NavigationRoute={this.NavigationRoute}
          curCityName={city_lable.length > 0 ? city_lable : curCity.label}
        />
        {/* 轮播图 */}
        <MyCarousel></MyCarousel>
        {/* 导航条 */}
        <MyNavigation NavigationRoute={this.NavigationRoute}></MyNavigation>
        {/* 推荐小组 */}
        <MyRentingGroup></MyRentingGroup>
        {/* 最新咨询 */}
        <MyNewx></MyNewx>
        {/* 结尾标签 */}
      </div>
    );
  }
}

export default connect((state) => {
  return { curCity: state.curCity };
}, {})(Index);
